import java.util.ArrayList;
import java.util.Comparator;

/**
 *
 * @author Zuzana Krejcova
 */
public class ComparatorNetermu implements Comparator<String>
{
    private Gramatika g;
    public ComparatorNetermu(Gramatika g)
    {
        super();
        this.g = g;
    }

    @Override
    public int compare(String s1, String s2)
    {
        int ret1 = 0;
        int ret2 = 0;
        if (!g.pravidla.containsKey(s1)) ret1 = 1;
        if (!g.pravidla.containsKey(s2)) ret2 = 1;
        if ((ret1 != 0)||(ret2 != 0))
            if (ret1 > ret2)
            {
                return 1;
            } else
            {
                if (ret2 > ret1)
                {
                    return -1;
                } else
                {
                    return 1;//0
                }
            }

        for (ArrayList<String> al:g.pravidla.get(s1))
        {
            if (al.get(0).equals(s2))
            {
                ret1 = -1;
                break;
            }
        }
        for (ArrayList<String> al:g.pravidla.get(s2))
        {
            if (al.get(0).equals(s1))
            {
                ret2 = -1;
                break;
            }
        }
        if ((ret1 != 0)||(ret2 != 0))
            if (ret1 == ret2)
            {
                return 1;//0
            } else
            {
                if (ret1 > ret2)
                {
                    return 1;
                } else
                {
                    return -1;
                }
            }
        return 1;//0
    }
}